import 'dart:io';
import 'dart:math';

import 'package:demo202112/utils/common_appbar.dart';
import 'package:flutter/material.dart';

/// @Author wywinstonwy
/// @Date 2022/6/6 8:33 上午
/// @Description: 

class asyncController extends StatefulWidget {
  const asyncController({Key? key}) : super(key: key);

  @override
  State<asyncController> createState() => _asyncControllerState();
}

class _asyncControllerState extends State<asyncController> {
  @override
  void initState() {

    // TODO: implement initState
    super.initState();
  }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: getAppBar("async"),
      body: ElevatedButton(onPressed: test , child: Text("测试异步")),
    );
  }
  void test(){
    for(var i=0;i<10;i++ ){
      test2(i);
    }
  }

  Future<void> test2(var name) async{
    final _random =  Random();
    int next(int min,int max)=>min+_random.nextInt(max-min);
    var c = next(0, 5);
    sleep(Duration(seconds: c));
    print(name);
  }
}
